from django.utils.deprecation import MiddlewareMixin
from rest_framework.response import  Response

class CorsMiddleware(MiddlewareMixin):
    def process_response(self, request, response:Response):
        response.headers["Access-Control-Allow-Origin"] = '*'
        if request.method == 'OPTIONS':
            response.headers["Access-Control-Allow-Credentials"] = True
            response.headers["Access-Control-Allow-Methods"] =  'GET, POST, OPTIONS,DELETE,PUT,PATCH'
            response.headers["Access-Control-Allow-Headers"] =  'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Access-Control-Allow-Origin'
        return response